package com.taorenqi.data.service;

import android.content.Context;

import com.taorenqi.data.common.BasePageableResponse;
import com.taorenqi.data.entity.login.CodeDataEntity;
import com.taorenqi.data.entity.login.LoginEntity;
import com.taorenqi.data.entity.mine.BannerListEntity;
import com.taorenqi.data.entity.mine.GiftEntity;
import com.taorenqi.data.entity.mine.MessageDetailEntity;
import com.taorenqi.data.entity.mine.MessageEntity;
import com.taorenqi.data.entity.mine.MoneyDetailEntity;
import com.taorenqi.data.entity.mine.PopularityEntity;
import com.taorenqi.data.entity.mine.RechargeRecordEntity;
import com.taorenqi.data.entity.mine.RechargeRecordVipEntity;
import com.taorenqi.data.entity.mine.UserCenterEntity;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by Administrator on 2017-06-12.
 */

public class MineDataHttpRequest extends HttpRequest {

    private static MineDataHttpRequest instants;
    private MineDataService service;

    private MineDataHttpRequest(Context context) {
        super(context);
        service = retrofit.create(MineDataService.class);
    }

    public static MineDataHttpRequest getInstance(Context context){
        if (instants == null){
            instants = new MineDataHttpRequest(context);
        }

        return instants;
    }


    /**
     * 用于取得资金明细数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param tkmtype      手机号
     * @param page    密码
     * @param pageSize      设备
     */
    public void getMoneyDetail(Subscriber<BasePageableResponse<MoneyDetailEntity>> subscriber, int tkmtype, int page, int pageSize,String sign)  {

        Observable observable = service.getMoneyDetail(tkmtype, page,DEFAULT_PAGE_SIZE,sign)
                .map(new HttpResultFunc<BasePageableResponse<MoneyDetailEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于取得人气值明细数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param type      手机号
     * @param page    密码
     * @param pageSize      设备
     */
    public void getPopularity(Subscriber<BasePageableResponse<PopularityEntity>> subscriber, int type, int page, int pageSize)  {

        Observable observable = service.getPopularity(type, page,DEFAULT_PAGE_SIZE)
                .map(new HttpResultFunc<BasePageableResponse<PopularityEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于取得我的礼券数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param type      手机号
     * @param page    密码
     * @param pageSize      设备
     */
    public void getGift(Subscriber<BasePageableResponse<GiftEntity>> subscriber, int type, int page, int pageSize,String sign)  {

        Observable observable = service.getGift(type, page,DEFAULT_PAGE_SIZE,sign)
                .map(new HttpResultFunc<BasePageableResponse<GiftEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于取gb充值记录数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param
     * @param page    密码
     * @param pageSize      设备
     */
    public void getGbRecharge(Subscriber<BasePageableResponse<RechargeRecordEntity>> subscriber,int page, int pageSize)  {

        Observable observable = service.getGbRecharge(page,DEFAULT_PAGE_SIZE)
                .map(new HttpResultFunc<BasePageableResponse<RechargeRecordEntity>>());

        toSubscribe(observable, subscriber);
    }


    /**
     * 用于取gb充值记录数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param
     * @param page    密码
     * @param pageSize      设备
     */
    public void getVipRecharge(Subscriber<BasePageableResponse<RechargeRecordVipEntity>> subscriber, int page, int pageSize)  {

        Observable observable = service.getVipRecharge(page,DEFAULT_PAGE_SIZE)
                .map(new HttpResultFunc<BasePageableResponse<RechargeRecordVipEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于取站内信息数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param
     */
    public void getMessage(Subscriber<BasePageableResponse<MessageEntity>> subscriber)  {

        Observable observable = service.getMessage()
                .map(new HttpResultFunc<BasePageableResponse<MessageEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于取站内信息详情数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param
     */
    public void getMessageDetail(Subscriber<BasePageableResponse<MessageDetailEntity>> subscriber, int news_type, int id)  {

        Observable observable = service.getMessageDetail(news_type,id)
                .map(new HttpResultFunc<BasePageableResponse<MessageDetailEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于取得用户数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     */
    public void getUserCenter(Subscriber<BasePageableResponse<UserCenterEntity>> subscriber)  {

        Observable observable = service.getUserCenter()
                .map(new HttpResultFunc<BasePageableResponse<UserCenterEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于取得banner数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     */
    public void getBannerList(Subscriber<BasePageableResponse<BannerListEntity>> subscriber)  {

        Observable observable = service.getBannerList()
                .map(new HttpResultFunc<BasePageableResponse<BannerListEntity>>());

        toSubscribe(observable, subscriber);
    }

}
